// pages/exchange/exchange.js
Page({

  data: {
    tab:0,
    classify:'/static/image/分类后.png',
    mine:'/static/image/我的.png',
    color:'',
    exchange:false,

    video_list:[],

  movie_list:[],

 life_list:[
  {image1:'/static/image/50话费.png',
  text1:'50元花费充值',
  value1:'6000',
  image2:'/static/image/30话费.png',
  text2:'30元花费充值',
  value2:'3600',
 }
 ],
 star_url:[{
   url:'/static/image/星星.png'
 },{
  url:'/static/image/星星.png'
 },{
  url:'/static/image/星星.png'
 },{
  url:'/static/image/星星.png'
 },{
  url:'/static/image/星星.png'
   
 }],
 other_list:[],
 hour:'100000',
 coin:'10000',
 ava:'',
 index:''

  },
  
  onLoad:function(){
    var ava = wx.getStorageSync('userInfo').avatarUrl
    this.setData({
      classify:'/static/image/分类后.png',
      mine:'/static/image/我的.png',
      color:0,
      ava:ava
    })
    wx.request({
      url: 'http://127.0.0.1:8082/demo1/superadmin/listitem',
      data:{},
      method:'GET',
      success:(res)=>{
        console.log(res)
        var list = res.data.ItemList
        var len = list.length
        // console.log(list[0].itemid[0])
        var video =[]
        var movie = []
        var life = []
        var other = []
    
        for(var i=0;i<len;i++){
          if(list[i].itemid[0] == 'm'){
              movie.push(list[i])
          }
          if(list[i].itemid[0] == 'i'){
            video.push(list[i])
          }
          if(list[i].itemid[0] == 'l'){
            life.push(list[i])
          }
          if(list[i].itemid[0] == 'b'){
            other.push(list[i])
          }
        }

        // console.log(life)

        /*视频会员*/
        var len_video = video.length
        var endvideo = []
        for(var i=0;i<len_video;i=i+2){
         
          var itemid1 = video[i].itemid
          var itemname1 = video[i].itemname
          var itemcoin1  = video[i].itemcoin
          var itempic1 = video[i].itempic
          var itemnum1 = video[i].itemnum
          if(i+1 < len_video){
            var itemid2 = video[i+1].itemid
            var itemname2 = video[i+1].itemname
            var itemcoin2  = video[i+1].itemcoin
            var itempic2 = video[i+1].itempic
            var itemnum2 = video[i+1].itemnum
            var hidden = false
          }else{
            var itemid2 = ''
            var itemname2 = ''
            var itemcoin2  = ''
            var itempic2 = ''
            var itemnum2 = ''
            var hidden = true
          }
          

        var arrvideo = {
           itemid1:itemid1,
           itemname1:itemname1,
           itemcoin1:itemcoin1,
           itempic1:itempic1,
           itemnum1:itemnum1,

           itemid2:itemid2,
           itemname2:itemname2,
           itemcoin2:itemcoin2,
           itempic2:itempic2,
           itemnum2:itemnum2,
           hidden:hidden
        }
        endvideo.push(arrvideo)
      }

        /*音频娱乐 */
        var  len_movie = movie.length
        var endmovie = []
        for(var i=0;i<len_movie;i=i+2){
         
            var itemid1 = movie[i].itemid
            var itemname1 = movie[i].itemname
            var itemcoin1  = movie[i].itemcoin
            var itempic1 = movie[i].itempic
            var itemnum1 = movie[i].itemnum
          
            if(i+1 < len_movie){
              var itemid2 = movie[i+1].itemid
              var itemname2 = movie[i+1].itemname
              var itemcoin2  = movie[i+1].itemcoin
              var itempic2 = movie[i+1].itempic
              var itemnum2 = movie[i+1].itemnum
              var hidden = false
            }else{
              var itemid2 = ''
              var itemname2 = ''
              var itemcoin2  = ''
              var itempic2 = ''
              var itemnum2 = ''
              var hidden = true
            }
           

          var arrmoive = {
             itemid1:itemid1,
             itemname1:itemname1,
             itemcoin1:itemcoin1,
             itempic1:itempic1,
             itemnum1:itemnum1,

             itemid2:itemid2,
             itemname2:itemname2,
             itemcoin2:itemcoin2,
             itempic2:itempic2,
             itemnum2:itemnum2,
             hidden:hidden
          }
          
          endmovie.push(arrmoive)
        }

        /*品质生活 */
        var len_life = life.length
        var endlife =[]
        for(var i=0;i<len_life;i=i+2){
         
          var itemid1 = life[i].itemid
          var itemname1 = life[i].itemname
          var itemcoin1  = life[i].itemcoin
          var itempic1 = life[i].itempic
          var itemnum1 = life[i].itemnum
          if(i+1 < len_life){
            var itemid2 = life[i+1].itemid
          var itemname2 = life[i+1].itemname
          var itemcoin2  = life[i+1].itemcoin
          var itempic2 = life[i+1].itempic
          var itemnum2 = life[i+1].itemnum
          var hidden = false
          }else{
              var itemid2 = ''
              var itemname2 = ''
              var itemcoin2  = ''
              var itempic2 = ''
              var itemnum2 = ''
              var hidden = true
          }
          

        var arrlife = {
           itemid1:itemid1,
           itemname1:itemname1,
           itemcoin1:itemcoin1,
           itempic1:itempic1,
           itemnum1:itemnum1,

           itemid2:itemid2,
           itemname2:itemname2,
           itemcoin2:itemcoin2,
           itempic2:itempic2,
           itemnum2:itemnum2,
           hidden:hidden
        }
        endlife.push(arrlife)
      }

        /*其他物品 */
        var len_other = other.length
        var endother =[]
        for(var i=0;i<len_other;i=i+2){
         
          var itemid1 = other[i].itemid
          var itemname1 = other[i].itemname
          var itemcoin1  = other[i].itemcoin
          var itempic1 = other[i].itempic
          var itemnum1 = other[i].itemnum
          if(i+1 < len_other){
            var itemid2 = other[i+1].itemid
          var itemname2 = other[i+1].itemname
          var itemcoin2  = other[i+1].itemcoin
          var itempic2 = other[i+1].itempic
          var itemnum2 = other[i+1].itemnum
          var hidden = false
          }else{
              var itemid2 = ''
              var itemname2 = ''
              var itemcoin2  = ''
              var itempic2 = ''
              var itemnum2 = ''
              var hidden = true
          }
          

        var arrother = {
           itemid1:itemid1,
           itemname1:itemname1,
           itemcoin1:itemcoin1,
           itempic1:itempic1,
           itemnum1:itemnum1,

           itemid2:itemid2,
           itemname2:itemname2,
           itemcoin2:itemcoin2,
           itempic2:itempic2,
           itemnum2:itemnum2,
           hidden:hidden
        }
        endother.push(arrother)
      }


        // console.log(endother)
        this.setData({
          movie_list:endmovie,
          video_list:endvideo,
          life_list:endlife,
          other_list:endother
        })
        

      }
    })
    


  },
  changeItem:function(e){
    this.setData({
      item:e.target.dataset.item
    })
  },
  
  changeTab:function(e){
    this.setData({
       tab:e.detail.current
    })
  },

  classify:function(){
    this.setData({
      classify:'/static/image/分类后.png',
      mine:'/static/image/我的.png',
      color:0,
      exchange:false
    })
  },

  mine:function(){
    this.setData({
      classify:'/static/image/分类.png',
      mine:'/static/image/我的无.png',
      color:1,
      exchange:true
    })
  },

  //video
  showvideo1:function(e){
    var index = this.data.index
    var list = this.data.video_list[index]
    console.log(this.data.video_list[index])
    var save = {
      image:list.image1,
      text:list.text1,
      value:list.value1
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  showvideo2:function(e){
    var index = this.data.index
    var list = this.data.video_list[index]
    console.log(this.data.video_list[index])
    var save = {
      image:list.image2,
      text:list.text2,
      value:list.value2
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  //movie
  showmovie1:function(e){
    var index = this.data.index
    var list = this.data.movie_list[index]
    console.log(this.data.movie_list[index])
    var save = {
      image:list.image1,
      text:list.text1,
      value:list.value1
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  showmovie2:function(e){
    var index = this.data.index
    var list = this.data.movie_list[index]
    console.log(this.data.movie_list[index])
    var save = {
      image:list.image2,
      text:list.text2,
      value:list.value2
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  //life
  showlife1:function(){
    var index = this.data.index
    var list = this.data.life_list[index]
    console.log(this.data.life_list[index])
    var save = {
      image:list.image1,
      text:list.text1,
      value:list.value1
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  showlife2:function(){
    var index = this.data.index
    var list = this.data.life_list[index]
    console.log(this.data.life_list[index])
    var save = {
      image:list.image2,
      text:list.text2,
      value:list.value
    }
    var data = JSON.stringify(save)
    wx.navigateTo({
      url: '/pages/order/order?list='+data,
    })
  },
  item:function(e){
    var index = e.currentTarget.dataset.index
    this.setData({
      index:index
    })
  }


})